package psn.zch.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import psn.zch.mapper.ZCustomerMapper;
import psn.zch.model.ZCustomer;

import java.util.List;

@Service
public class ZCustomerService {

    @Autowired
    private ZCustomerMapper zCustomerMapper;

    @Transactional(rollbackFor = Exception.class)
    public int insert(List<ZCustomer> list) {

        if (list.size() > 1) {

            zCustomerMapper.insertSelective(list.get(0));

            throw new RuntimeException();
        } else {

            list.forEach(zCustomerMapper::insertSelective);
        }

        return list.size();
    }
}
